package keye.document_manage.gui;

import java.util.List;
import java.util.concurrent.ExecutionException;

import javax.swing.SwingWorker;

import keye.document_manage.entity.SelectParameters;
import keye.document_manage.service.IFilesCheckService;
import keye.document_manage.util.ConvertStringUtil;

public class CheckDataView extends SwingWorker<String, String>{

	private ProgressFrame progressFrame;
	private List<SelectParameters> selectParas;
	private String osPosition;
	private String  logPath;
	private String[] tableNames;
	private IFilesCheckService filesCheckService;
	
	public CheckDataView() {
	}

	public CheckDataView(IFilesCheckService filesCheckService,ProgressFrame progressFrame,
			List<SelectParameters> selectParas, 
			String osPosition, String logPath,String... tableNames) {
		this.filesCheckService = filesCheckService;
		this.progressFrame = progressFrame;
		this.selectParas = selectParas;
		this.osPosition = osPosition==null?"":osPosition;
		this.logPath = logPath;
		this.tableNames = tableNames;
	}
	
	@Override
	protected String doInBackground() throws Exception {
		long startTime=System.currentTimeMillis();   //获取开始时间
		filesCheckService.checkFiles(progressFrame, osPosition, logPath, selectParas, tableNames);
		long endTime=System.currentTimeMillis(); //获取结束时间
		return ConvertStringUtil.convertTime(endTime-startTime);
	}

	@Override
	protected void done() {
		try {
			progressFrame.addOneComplete(tableNames[0], get(),logPath);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}

}
